import { ExtendedRouteRecordRaw } from '../utils/types'
import { toFlatRoutes, updateRouteMetaInfo } from '../utils/route-utils'

import IconOverview from '../assets/imgs/overview.png'
import IconRegister from '../assets/imgs/register.png'
import IconManage from '../assets/imgs/manage.png'
import IconManageBlack from '../assets/imgs/manage_black.png'
import IconLog from '../assets/imgs/log.png'
import IconLogBlack from '../assets/imgs/log_black.png'

const ComCreate = () => import('../pages/apis/Create.vue')

const myRoutes: ExtendedRouteRecordRaw[] = [
  {
    path: '/create',
    component: ComCreate,
    meta: { title: 'API创建', icon: IconRegister }
  },
  {
    path: '/apis',
    meta: { title: 'API列表', icon: IconOverview },
    children: [
      {
        path: '',
        component: () => import('../pages/apis/Index.vue'),
        meta: { notSubMenu: true }
      },
      {
        path: 'edit/:id',
        component: ComCreate,
        meta: { title: '编辑', notSubMenu: true }
      },
      {
        path: 'add',
        component: ComCreate,
        meta: { title: '新增', notSubMenu: true }
      }
    ] as ExtendedRouteRecordRaw[]
  },
  {
    path: '/manage',
    meta: { title: 'API管理', subTitle: 'API管理', icon: IconManage, activeIcon: IconManageBlack },
    children: [
      {
        path: 'custom',
        component: () => import('../pages/manage/Custom.vue'),
        meta: { title: '客户管理' , icon: IconRegister}
      },
      {
        path: 'plug',
        component: () => import('../pages/manage/Plug.vue'),
        meta: { title: '插件管理' , icon: IconRegister}
      }
    ]
  },
  {
    path: '/gateway-strategy',
    component: () => import('../pages/rule/MeasureRule.vue'),
    meta: { title: '网关控制策略' , subTitle: '网关控制策略', icon: IconManage, activeIcon: IconManageBlack },
    children: [
      {
        path: 'flow-strategy',
        component: () => import('../pages/strategy/FlowStrategy.vue'),
        meta: { title: '流量控制策略' }
      },
      {
        path: 'access-strategy',
        component: () => import('../pages/strategy/AccessStrategy.vue'),
        meta: { title: '访问控制策略' }
      }
    ]
  },
  {
    path: '/measure-rule',
    component: () => import('../pages/rule/MeasureRule.vue'),
    meta: { title: '计量规则' , icon: IconRegister}
  },
  {
    path: '/log',
    meta: { title: '日志管理', subTitle: '日志管理', icon: IconLog, activeIcon: IconLogBlack },
    children: [
      {
        path: 'sys-login',
        component: () => import('../pages/log/SysLogin.vue'),
        meta: { title: '系统登录日志' }
      },
      {
        path: 'sys-operate',
        component: () => import('../pages/log/SysOperate.vue'),
        meta: { title: '系统操作日志' }
      },
      {
        path: 'api-call',
        component: () => import('../pages/log/ApiCall.vue'),
        meta: { title: 'API调用日志' }
      }
    ]
  },
  {
    path: '/dict',
    component: () => import('../pages/dict/Index.vue'),
    meta: { title: '字典管理', icon: IconRegister }
  },
  {
    path: '/test/:apiId',
    component: () => import('../pages/test/Index.vue'),
    meta: { title: 'API测试' }
  }
]

export const rawRoutes = updateRouteMetaInfo(myRoutes)

export const routes = toFlatRoutes(rawRoutes)
